package cc.rengu.redp.bizimpl.csmc.controller;


import cc.rengu.redp.bizimpl.csmc.domain.CInstructionRule;
import cc.rengu.redp.bizimpl.csmc.service.ICInstructionRuleService;
import cc.rengu.redp.bizimpl.csmc.vo.CInstructionRuleVO;
import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author lizk
 */
@RestController
@Slf4j
@RequestMapping("/admin/csmc/cInstructionRule")
public class CInstructionRuleController extends BaseController {

    @Autowired
    private ICInstructionRuleService instructionRuleService;


    @GetMapping
    public Map<String, Object> findByPage(QueryRequest queryRequest, CInstructionRule instructionRule) {
        return instructionRuleService.findByPage(queryRequest, instructionRule);
    }

    @GetMapping("/cInstructionRuleDialog")
    public Map<String, Object> cInstructionRuleDialog(QueryRequest queryRequest, CInstructionRule instructionRule) {
        return getDataTable(instructionRuleService.cInstructionRuleDialog(queryRequest, instructionRule));
    }

    @Log("新增/修改/停用/启用 清分规则")
    @PostMapping
//    @RequiresPermissions("brand:add")
    public void createAcctEntry(@RequestBody CInstructionRuleVO instructionRuleVO) throws RedpException {

        try {
            this.instructionRuleService.adminCInstructionRule(instructionRuleVO.getInstructionRuleList(), instructionRuleVO.getOptFlag());
        } catch (Exception e) {
            String message = e.getMessage();
            log.error(message, e);
            throw new RedpException(message);
        }

    }

}
